﻿using MediatR;
using SmartProduction.Domain;
using SmartProduction.ErrorCode;
using SmartProduction.Infarstructrue.Interface;
using SmartProduction.Read.API.Application.Commands.ManifestCommand;

namespace SmartProduction.Read.API.Application.CommandHandlers.ManifestCommandHandler
{
    public class ManifestGetCommandHandler : IRequestHandler<ManifestGetCommand, APIResult<List<Manifest>>>
    {
        private readonly IBaseRepository<Manifest> maniRepository;

        public ManifestGetCommandHandler(IBaseRepository<Manifest> maniRepository)
        {
            this.maniRepository = maniRepository;
        }

        public async Task<APIResult<List<Manifest>>> Handle(ManifestGetCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Manifest>> result=new APIResult<List<Manifest>>();
            result.Code=APIEnums.查询成功;
            result.Msg= APIEnums.查询成功.ToString();
            var query=maniRepository.GetAll().Result;
            result.data = query.ToList();
           return await Task.FromResult(result);
        }
    }
}
